package com.dup.jxlh.admin.service.impl;

import com.dup.jxlh.admin.mapper.DictionaryDataMapper;
import com.dup.jxlh.admin.service.DictionaryDataService;
import com.dup.jxlh.api.entities.DictionaryData;
import com.dup.jxlh.api.enums.*;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.ArrayList;

@Service("dataDictionaryServiceImpl")
public class DictionaryDataServiceImpl implements DictionaryDataService {
    @Resource
    private DictionaryDataMapper dataDictionaryMapper;

    @Override
    @Cacheable(value = "level")
    public ArrayList<DictionaryData> getLevelData() {
        ArrayList<DictionaryData> data = new ArrayList<>();
        for (LevelEnum stateEnum : LevelEnum.values()) {
            DictionaryData dictionaryData = new DictionaryData();
            dictionaryData.setId(stateEnum.getCode());
            dictionaryData.setName(stateEnum.getName());
            data.add(dictionaryData);
        }
        return data;
    }

    @Override
    @Cacheable(value = "contracttype")
    public ArrayList<DictionaryData> getContractTypeData() {
        ArrayList<DictionaryData> levelData = new ArrayList<>();
        for (ContractTypeEnum stateEnum : ContractTypeEnum.values()) {
            DictionaryData dictionaryData = new DictionaryData();
            dictionaryData.setId(stateEnum.getCode());
            dictionaryData.setName(stateEnum.getName());
            levelData.add(dictionaryData);
        }
        return levelData;
    }

    @Override
    public ArrayList<DictionaryData> getCompanyData(BigInteger companyId) {
        return dataDictionaryMapper.getCompanyData(companyId);
    }

    @Override
    public ArrayList<DictionaryData> getDepartmentData(BigInteger companyId) {
        return dataDictionaryMapper.getDepartmentData(companyId);
    }

    @Override
    public ArrayList<DictionaryData> getDepartmentById(BigInteger id) {
        return dataDictionaryMapper.getDepartmentById(id);
    }

    @Override
    public ArrayList<DictionaryData> getRoleData(BigInteger companyId) {
        return dataDictionaryMapper.getRoleData(companyId);
    }

    @Override
    @Cacheable(value = "chapterapplystatus")
    public ArrayList<DictionaryData> getChapterApplyStatusData() {
        ArrayList<DictionaryData> data = new ArrayList<>();
        for (ChapterApplyStatusEnum stateEnum : ChapterApplyStatusEnum.values()) {
            DictionaryData dictionaryData = new DictionaryData();
            dictionaryData.setId(stateEnum.getCode());
            dictionaryData.setName(stateEnum.getName());
            data.add(dictionaryData);
        }
        return data;
    }

    @Override
    @Cacheable(value = "chapterapplytype")
    public ArrayList<DictionaryData> getChapterApplyTypeData() {
        ArrayList<DictionaryData> data = new ArrayList<>();
        for (ChapterApplyTypeEnum stateEnum : ChapterApplyTypeEnum.values()) {
            DictionaryData dictionaryData = new DictionaryData();
            dictionaryData.setId(stateEnum.getCode());
            dictionaryData.setName(stateEnum.getName());
            data.add(dictionaryData);
        }
        return data;
    }

    @Override
    @Cacheable(value = "chaptertype")
    public ArrayList<DictionaryData> getChapterTypeData() {
        ArrayList<DictionaryData> data = new ArrayList<>();
        for (ChapterTypeEnum stateEnum : ChapterTypeEnum.values()) {
            DictionaryData dictionaryData = new DictionaryData();
            dictionaryData.setId(stateEnum.getCode());
            dictionaryData.setName(stateEnum.getName());
            data.add(dictionaryData);
        }
        return data;
    }

    @Override
    public ArrayList<DictionaryData> getAdminData(BigInteger companyId) {
        return dataDictionaryMapper.getAdminData(companyId);
    }
}
